// pkgTask/pages/takephoto-task-list/index.js
const lbbTaskService = require('../service/task-service.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    // photoList: [
    //   {
    //     id: 1,
    //     type: 'image',
    //     url: 'https://img2.baidu.com/it/u=568058143,60159047&fm=253&fmt=auto&app=138&f=JPEG?w=375&h=500'
    //   },
    //   {
    //     id: 2,
    //     type: 'image',
    //     url: 'https://img2.baidu.com/it/u=2164404601,3658970489&fm=253&fmt=auto&app=120&f=JPEG?w=664&h=500'
    //   },
    //   {
    //     id: 3,
    //     type: 'image',
    //     url: 'https://img0.baidu.com/it/u=3264529111,1165982806&fm=253&fmt=auto&app=138&f=JPEG?w=734&h=500'
    //   },
    //   {
    //     id: 4,
    //     type: 'image',
    //     url: 'https://img1.baidu.com/it/u=1911538943,1117537492&fm=253&fmt=auto&app=138&f=JPEG?w=390&h=500'
    //   }
    // ],
    photoList: [
      {
        id: 1,
        type: 'video',
        url: 'https://litemall-admin-001.oss-cn-hangzhou.aliyuncs.com/imagec676550aa49030c8cc5a67684cfa45fc-1486972083736023040.mp4'
      },
      {
        id: 2,
        type: 'video',
        url: 'https://litemall-admin-001.oss-cn-hangzhou.aliyuncs.com/image用户订单列表-门店自提-无软链锁-1486972265596850176.mp4'
      },
      {
        id: 3,
        type: 'video',
        url: 'https://litemall-admin-001.oss-cn-hangzhou.aliyuncs.com/image1640170226033932-1486972521235484672.mp4'
      },
      {
        id: 4,
        type: 'image',
        url: 'https://img1.baidu.com/it/u=1911538943,1117537492&fm=253&fmt=auto&app=138&f=JPEG?w=390&h=500'
      }
    ],
    recordId:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.data.recordId = options.id
      this.setData({
        equId: options.equId,
        lockType: options.lockType
      })
      this.getEquPhotoFiles()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      // this.videoContext = wx.createVideoContext('myVideo')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onSwiperChange(e) {
    this.setData({
      current: e.detail.current
    })
  },

  prviewImage(e) {
    console.log(e)
    let urls = []
    urls.push(this.data.photoList[e.target.dataset.index])
    wx.previewMedia({
      sources: urls,
    })
  },

  

  /**
   * 审核通过
   */ 
  passPhoto() {
    let that = this  
    lbbTaskService.photoCheckRst({
      equRecordId: that.data.recordId,
      checkStat: 1
      },
      function(res) {
       wx.showToast({
         title: res.result == 0 ? '提交成功' : '提交失败',
       })
    })

  },

  /**
   * 审核不通过
   */
  rejectPhoto() {

    let that = this  
    lbbTaskService.photoCheckRst({
      equRecordId: that.data.recordId,
      checkStat: 2
      },
      function(res) {
       wx.showToast({
         title: res.result == 0 ? '提交成功' : '提交失败',
       })
    })

  },

  getEquPhotoFiles() {

    let that = this
    lbbTaskService.getEquPhotoFiles({
      equRecordId: that.data.recordId
    }, function(res) {
       that.setData({
         photoList: res.data
       })
    })
  },


})